<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
else
    
    //Add tank form option
    include 'waterchange.html';

    
    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
       
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());
    
    //Variables
    $tanktype = $_POST['tanktype'];
    $qty = $_POST['qty'];
    $salt = $_POST['salt'];
    
    //Date variables
    $day = $_POST['day'];
    $month = $_POST['month'];
    $year = $_POST['year'];
    
    //Date variables
    $day2 = $_POST['day2'];
    $month2 = $_POST['month2'];
    $year2 = $_POST['year2'];
    
    //Function to make a valid date input
    $changedate = $year."-".$month."-".$day;
    $nextchangedate = $year2."-".$month2."-".$day2;
    
    //SQL Query to add tank info
    $add_waterchange = "insert into waterchange (change_date,next_change,quantity,tank,salt_used,user_id) values ('$changedate','$nextchangedate','$qty','$tanktype','$salt','". $_SESSION['uid'] ."')";
  
        //Execute Insert command
        if (!mysql_query($add_waterchange,$con))
            {
              die('Error: ' . mysql_error());
            }
            echo "Water change added successfully!"; 
               
    //Close SQL input
    mysql_close($con);
?>